package weibo

import (
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"time"
)

type Info struct {
	Nowday int
}

var (
	info Info
)

func Racall() {
	Path, _ = filepath.Abs("./log")
	SetSavePath()
	defer func(f *os.File) {
		err := f.Close()
		if err != nil {
		}
	}(f)
	// 启动时间
	info.Nowday = time.Now().YearDay()
	for {
		// 如果过了一天
		if info.Nowday < time.Now().YearDay() {
			Lock.Lock()
			// 切换保存的数据
			err := f.Close()
			// 修改之前的文件名
			timer := time.Now().Format("20060102")
			newpath := strings.Replace(Path+"/now.csv", "now", timer, -1)
			err = os.Rename(Path+"/now.csv", newpath)
			f, err = os.OpenFile(Path+"/now.csv", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
			if err != nil {
				fmt.Println("新建文件失败 -- >", newpath)
				return
			}
			// 新建文件完成
			info.Nowday = time.Now().YearDay()
			// 解锁
			Lock.Unlock()
		}
		//go Init()
		go get()
		time.Sleep(10 * time.Minute)
		//Jx()
	}

}
